package com.lagou.pojo;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.Table;

@Data
@Document(indexName = "lagou",type = "product",shards = 3,replicas = 1)
public class Product {
    @Id //作为document的id
    private Long id;
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String name; //名称
    @Field(type = FieldType.Keyword)
    private String flag;// 标志
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String goods_desc; // 描述
    @Field(type = FieldType.Double)
    private Double price; // 价格
    @Field(type = FieldType.Keyword,index = false)
    private String images; // 图片地址
    @Field(type = FieldType.Integer)
    private Integer goods_stock;
    @Field(type = FieldType.Keyword)
    private String goods_type;

    public Product() {

    }


    public static com.lagou.db.Product converter(Product product){
        if(product == null){
            return null;
        }

        return com.lagou.db.Product.builder()
                .flag(product.getFlag())
                .goodsDesc(product.getGoods_desc())
                .goodsStock(product.getGoods_stock())
                .goodsType(product.getGoods_type())
                .id(product.getId())
                .images(product.getImages())
                .name(product.getName())
                .price(product.getPrice())
                .build();
    }


}
